#pragma once

#include <dirent.h>
#include <stdlib.h>
#include <sys/stat.h>

#include "Dataset.h"

class Testset : public virtual Dataset
{
private:
protected:
    vector<palmprint> datas;
    virtual int get_person_id(string filename) const = 0;

public:
    using Dataset::Dataset;
    //Testset(string dir) : Dataset(dir){};
    ~Testset(){};

    virtual void load() = 0;

    class iterator : virtual Dataset::iterator
    {
    private:
        vector<palmprint>::iterator i;

    public:
        //iterator(){};
        iterator(vector<palmprint>::iterator &i) : i(i){};
        iterator(const Testset::iterator &src)
        {
            this->i = vector<palmprint>::iterator(src.i.base());
        };
        ~iterator(){};

        palmprint &operator*() const
        {
            return *i;
        }
        palmprint *operator->() const
        {
            return i.base();
        }
        iterator &operator++()
        {
            ++i;
            return *this;
        }
        //ugly code,don't call this method
        iterator &operator++(int)
        {
            static iterator *cpy_i;

            vector<palmprint>::iterator tmp = vector<palmprint>::iterator(i.base());
            i++;

            if (cpy_i != NULL)
                delete cpy_i;
            cpy_i = new iterator(tmp);

            return *cpy_i;
        }

        bool operator==(const iterator &arg) const
        {
            return arg.i == this->i;
        }

        bool operator!=(const iterator &arg) const
        {
            return arg.i != this->i;
        }
    };

    iterator begin()
    {
        vector<palmprint>::iterator tmp = datas.begin();
        iterator a(tmp);
        return a;
    }

    iterator end()
    {
        vector<palmprint>::iterator tmp = datas.end();
        iterator a(tmp);
        return a;
    }

    int size()
    {
        return datas.size();
    }
};
